//
//  TitleBtn.m
//  微博---
//
//  Created by administrator on 14-11-13.
//  Copyright (c) 2014年 fly. All rights reserved.
//

#import "TitleBtn.h"

@implementation TitleBtn

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageView.contentMode=UIViewContentModeCenter;
        self.titleLabel.textAlignment=NSTextAlignmentRight;
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    return self;
}
//设置按钮图片的frame
-(CGRect)imageRectForContentRect:(CGRect)contentRect{
      CGFloat imageY=3;
    CGFloat imageH=self.frame.size.height-3;
    CGFloat imageW=imageH;
    CGFloat imageX=self.frame.size.width-imageW-3;

    return CGRectMake(imageX, imageY, imageW, imageH);
}
//设置按钮标题的frame
-(CGRect)titleRectForContentRect:(CGRect)contentRect{
    CGFloat titleX=0;
    CGFloat titleY=0;

    CGFloat titleW=self.frame.size.width-self.frame.size.height;

    CGFloat titleH=self.frame.size.height;

    return CGRectMake(titleX, titleY, titleW, titleH);
}
-(void)setTitle:(NSString *)title forState:(UIControlState)state{
    [super setTitle:title forState:state];
    CGSize titleSize=[title sizeWithFont:self.titleLabel.font];
    CGRect tempFrame=self.frame;
    tempFrame.size.width=titleSize.width+self.frame.size.height+10;
    tempFrame.size.height=30;
    self.frame=tempFrame;
}
-(void)setSelected:(BOOL)selected
{
    [super setSelected:selected];
    if (selected) {
        self.imageView.transform = CGAffineTransformMakeRotation(M_PI);
    }else
    {
        self.imageView.transform = CGAffineTransformMakeRotation(0);

    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
